package com.stone.stone_mall.controller;

import com.stone.stone_mall.common.CommonResult;
import com.stone.stone_mall.nosql.mongodb.document.MemberReadHistory;
import com.stone.stone_mall.nosql.mongodb.service.MemberReadHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = {"会员浏览记录管理"})
@RequestMapping("/member/readHistory")
public class MemberReadHistoryController {
    @Autowired
    private MemberReadHistoryService memberReadHistoryService;

    @ApiOperation("创建浏览记录")
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public CommonResult create(@RequestBody MemberReadHistory memberReadHistory){
        int count=memberReadHistoryService.create(memberReadHistory);
        if(count>0){
            return CommonResult.success(count,"插入浏览记录成功");
        }

        return CommonResult.failed("插入浏览记录失败");
    }

    @ApiOperation("删除浏览历史记录")
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public CommonResult delete(@RequestParam("ids")List<String>ids){
        int count=memberReadHistoryService.delete(ids);
        if (count>0){
            return CommonResult.success(count,"删除浏览历史记录成功");
        }

        return CommonResult.failed("删除浏览历史记录失败");
    }

    @ApiOperation("展示历史浏览记录")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public CommonResult list(Long memberId){
        List<MemberReadHistory> readHistorieslist = memberReadHistoryService.list(memberId);
        return CommonResult.success(readHistorieslist,"ok");
    }


}
